//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - Properties
//===================================================================================


namespace App.Domain.Handlers {
    using System;
    using App.Data;
    using App.Domain.Contracts;
    using App.Domain.Models;

    public class CreateApplication {
        private readonly IApplicationRepository _applicationRepository;

        public CreateApplication(IApplicationRepository applicationRepository) {
            _applicationRepository = applicationRepository;
        }

        public void Execute(Guid userId, ICreateApplicationCommand applicationForm) {
            if (applicationForm == null)
                throw new ArgumentNullException("applicationForm");

            try {
                var application = applicationForm.ConvertToEntity();
                _applicationRepository.Create(application);
            }
            catch (InvalidOperationException ex) {
                throw new BusinessServicesException("UnableToCreateVehicleExceptionMessage", ex);
            }
        }
    }
}
